﻿using System.Web.Routing;
using Nop.Core.Plugins;
using Nop.Services.Localization;
using Nop.Web.Framework.Menu;
using Nop.Core;
using System.Linq;

namespace Nop.Plugin.Misc.ECustomerList
{
    public class ECustomerListPlugin : BasePlugin, IAdminMenuPlugin
    {
        #region Fields
        private readonly IWorkContext _workContext;
        #endregion

        #region Ctor

        public ECustomerListPlugin(IWorkContext workContext)
        {
            this._workContext = workContext;
        }

        #endregion

        #region Methods

        public override void Install()
        {

            //locals
            this.AddOrUpdatePluginLocaleResource("Plugins.Misc.ECustomerList.Active", "Active");
            this.AddOrUpdatePluginLocaleResource("Plugins.Misc.ECustomerList.NotActive", "Not active");
            this.AddOrUpdatePluginLocaleResource("Plugins.Misc.ECustomerList.ShowDeleted", "Show deleted");
            this.AddOrUpdatePluginLocaleResource("Plugins.Misc.ECustomerList.InternalCustomersOnly", "Internal customers");
            this.AddOrUpdatePluginLocaleResource("Plugins.Misc.ECustomerList.ExternalCustomersOnly", "External customers");
            this.AddOrUpdatePluginLocaleResource("Plugins.Misc.ECustomerList.MoreSearchOptions", "More options");
            this.AddOrUpdatePluginLocaleResource("Plugins.Misc.ECustomerList.ExternalSearchOptions", "External / Interanl");
            this.AddOrUpdatePluginLocaleResource("Plugins.Misc.ECustomerList.MoreSearchOptions.Hint", "More options");
            this.AddOrUpdatePluginLocaleResource("Plugins.Misc.ECustomerList.ExternalSearchOptions.Hint", "External / Interanl");
            this.AddOrUpdatePluginLocaleResource("Plugins.Misc.ECustomerList.Field.ExternalInternal", "External / Interanl");

            base.Install();
        }

        public override void Uninstall()
        {

            //locales
            this.DeletePluginLocaleResource("Plugins.Misc.ECustomerList.Active");
            this.DeletePluginLocaleResource("Plugins.Misc.ECustomerList.NotActive");
            this.DeletePluginLocaleResource("Plugins.Misc.ECustomerList.ShowDeleted");
            this.DeletePluginLocaleResource("Plugins.Misc.ECustomerList.InternalCustomersOnly");
            this.DeletePluginLocaleResource("Plugins.Misc.ECustomerList.ExternalCustomersOnly");
            this.DeletePluginLocaleResource("Plugins.Misc.ECustomerList.MoreSearchOptions");
            this.DeletePluginLocaleResource("Plugins.Misc.ECustomerList.ExternalSearchOptions");
            this.DeletePluginLocaleResource("Plugins.Misc.ECustomerList.MoreSearchOptions.Hint");
            this.DeletePluginLocaleResource("Plugins.Misc.ECustomerList.ExternalSearchOptions.Hint");
            this.DeletePluginLocaleResource("Plugins.Misc.ECustomerList.Field.ExternalInternal");

            base.Uninstall();
        }

        /// <summary>
        /// Gets a route for provider configuration
        /// </summary>
        /// <param name="actionName">Action name</param>
        /// <param name="controllerName">Controller name</param>
        /// <param name="routeValues">Route values</param>
        public void GetConfigurationRoute(out string actionName, out string controllerName, out RouteValueDictionary routeValues)
        {
            actionName = "Configure";
            controllerName = "MiscECustomerList";
            routeValues = new RouteValueDictionary() { { "Namespaces", "Nop.Plugin.Misc.ECustomerList.Controllers.Controllers" }, { "area", null } };
        }

        public void ManageSiteMap(SiteMapNode rootNode)
        {
            var menuItem = new SiteMapNode()
            {
                SystemName = "Hz",
                Title = "Extended Customer List",
                ControllerName = "MiscECustomerList",
                ActionName = "List",
                Visible = true,
                RouteValues = new RouteValueDictionary() { { "area", null } },
            };

            var pluginNode = rootNode.ChildNodes.FirstOrDefault(x => x.SystemName == "Third party plugins");
            if(pluginNode != null)
                pluginNode.ChildNodes.Add(menuItem);
            else
                rootNode.ChildNodes.Add(menuItem);
        }


        #endregion
    }
}
